/// @tags:
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 3e5 + 2;

int a[maxn];

int ecnt;
int heads[maxn * 2];

struct Edge {
  int v, nxt;
} e[maxn * 2 * 20];

inline void add(int u, int v) {
  e[++ecnt].v = v, e[ecnt].nxt = heads[u], heads[u] = ecnt;
}

int n, cnt;

bool vis[maxn];
int pri[maxn], minp[maxn], pid[maxn];
int dis[maxn * 2], prev[maxn * 2];

int main() {
  cin >> n;
  for (int i = 2; i < maxn; ++i) {
    if (!minp[i]) {
      minp[i] = i;
      pri[++pri[0]] = i;
      pid[i] = pri[0];
    }
    for (int j = 1; j <= pri[0] && i * pri[j] < maxn; ++j) {
      minp[i * pri[j]] = pri[j];
      if (pri[j] == minp[i]) break;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    while (a[i] != 1) {
      int prime = minp[a[i]];
      add(i, n + pid[prime]), add(n + pid[prime], i);
      while (a[i] % prime == 0) {
        a[i] /= prime;
      }
    }
  }
  int s, t;
  cin >> s >> t;
  memset(dis, 0x3f, sizeof(dis));
  dis[s] = 1;
  std::queue<int> q;
  q.emplace(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = heads[x]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (dis[v] == 0x3f3f3f3f) {
        dis[v] = dis[x] + (v <= n ? 0 : 1);
        prev[v] = x;
        q.emplace(v);
      }
    }
  }
  if (dis[t] == 0x3f3f3f3f) {
    cout << -1 << '\n';
  } else {
    cout << dis[t] << '\n';
    std::vector<int> ans;
    int u = t;
    ans.push_back(t);
    while (u != s) {
      u = prev[u];
      if (u > n) continue;
      ans.push_back(u);
    }
    std::reverse(ans.begin(), ans.end());
    for (auto i : ans) {
      cout << i << ' ';
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("D. Friendly Spiders.in", "r", stdin);
  freopen("D. Friendly Spiders.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
